package com.itheima.bos.web.action.system;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.itheima.bos.domain.system.Role;
import com.itheima.bos.service.system.IRoleService;
import com.itheima.bos.web.action.base.BaseAction;
import com.opensymphony.xwork2.ActionContext;

/**
 * 处理角色的action
 * @author yanju
 *
 */
@ParentPackage("json-default")
@Namespace("/")
@Scope("prototype")
@Controller
public class RoleAction extends BaseAction<Role>{
	
	@Autowired
	private IRoleService roleServiceImpl;
	
	@Action(value="role_list",results={@Result(name="success",type="json")})
	public String role_list(){
		
		List<Role> results=roleServiceImpl.findAll();
		
		ActionContext.getContext().getValueStack().push(results);
		return "success";
		
	}
	
	private String[] permissionIds;
	private String meniIds;

	public void setPermissionIds(String[] permissionIds) {
		this.permissionIds = permissionIds;
	}

	public void setMeniIds(String meniIds) {
		this.meniIds = meniIds;
	}




	@Action(value="role_save",results={@Result(name="success",type="redirect",location="/pages/system/role.html")})
	public String role_save(){
		
		roleServiceImpl.save(model,permissionIds,meniIds);
		
		
		return SUCCESS;
	}
}
